package mystatic.src.LT.IChoice;

import mystatic.src.LT.Book.Book;
import mystatic.src.LT.Book.BookList;

import java.util.Scanner;

public class Return implements IChoice {
    @Override
    public void work(BookList bookList) {
        System.out.println("您正在访问归还图书界面");
        System.out.println("请输入您需要归还的图书的名字");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        int i;
        for(i=0;i< bookList.getCnt();i++){
            Book books=bookList.getBook(i);
            if(books.getTitle().equals(name)){
                if(books.isBorrowed()==true){
                    books.setBorrowed(false);
                    System.out.println("归还成功 欢迎您再次借阅 谢谢");
                    return;
                }
                else{
                    System.out.println("该书已在书库 无需归还");
                }

            }
        }
        if(i==bookList.getCnt()-1){
            System.out.println("未找到您需要归还的书名");
        }
    }
}
